home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using a Pen to Draw Lines and Shapes / Drawing a Custom Dashed Line / GDITEST24.dpr
Encoding:
Text File  |  2003-10-15  |  2.3 KB  |  92 lines

  1. program GDITEST24;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   graphics : TGPGraphics;
  14.   pen: TGPPen;
  15. const
  16.   dash : array[0..3] of single = (5, 2, 15, 4);
  17. begin
  18.   graphics := TGPGraphics.Create(DC);
  19.   pen:= TGPPen.Create(MakeColor(255, 0, 0, 0), 5);
  20.   Pen.SetDashPattern(@dash, 4);
  21.   graphics.DrawLine(Pen, 5, 5, 405, 5);
  22.   pen.Free;
  23.   graphics.Free;
  24. end;
  25.  
  26.  
  27. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  28. var
  29.   Handle: HDC;
  30.   ps: PAINTSTRUCT;
  31. begin
  32.   case message of
  33.     WM_PAINT:
  34.       begin
  35.         Handle := BeginPaint(Wnd, ps);
  36.         OnPaint(Handle);
  37.         EndPaint(Wnd, ps);
  38.         result := 0;
  39.       end;
  40.  
  41.     WM_DESTROY:
  42.       begin
  43.         PostQuitMessage(0);
  44.         result := 0;
  45.       end;
  46.  
  47.    else
  48.       result := DefWindowProc(Wnd, message, wParam, lParam);
  49.    end;
  50. end;
  51.  
  52. var
  53.   hWnd     : THandle;
  54.   Msg      : TMsg;
  55.   wndClass : TWndClass;
  56. begin
  57.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  58.    wndClass.lpfnWndProc    := @WndProc;
  59.    wndClass.cbClsExtra     := 0;
  60.    wndClass.cbWndExtra     := 0;
  61.    wndClass.hInstance      := hInstance;
  62.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  63.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  64.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  65.    wndClass.lpszMenuName   := nil;
  66.    wndClass.lpszClassName  := 'GettingStarted';
  67.  
  68.    RegisterClass(wndClass);
  69.  
  70.    hWnd := CreateWindow(
  71.       'GettingStarted',       // window class name
  72.       'Drawing a Custom Dashed Line',      // window caption
  73.       WS_OVERLAPPEDWINDOW,    // window style
  74.       Integer(CW_USEDEFAULT), // initial x position
  75.       Integer(CW_USEDEFAULT), // initial y position
  76.       Integer(CW_USEDEFAULT), // initial x size
  77.       Integer(CW_USEDEFAULT), // initial y size
  78.       0,                      // parent window handle
  79.       0,                      // window menu handle
  80.       hInstance,              // program instance handle
  81.       nil);                   // creation parameters
  82.  
  83.    ShowWindow(hWnd, SW_SHOW);
  84.    UpdateWindow(hWnd);
  85.  
  86.    while(GetMessage(msg, 0, 0, 0)) do
  87.    begin
  88.       TranslateMessage(msg);
  89.       DispatchMessage(msg);
  90.    end;
  91. end.
  92.